package com.boot.pipeline;

import java.time.LocalDateTime;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.boot.bean.DetailPic;
import com.boot.bean.Seven;
import com.boot.util.DateTimeStyle;
import com.boot.util.JudgeUtil;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;


@PipelineName("getSomeInfo")
public class DoSomething implements Pipeline<Seven> {

	public void process(Seven bean) {
		LocalDateTime startTime = LocalDateTime.now();

		HttpRequest currRequest = bean.getRequest();

		if (JudgeUtil.isPresent(bean)) {
			List<DetailPic> detailPicList = bean.getP().getLi();
			detailPicList.forEach(a -> {
				if (JudgeUtil.isPresent(a)) {
					getNextPage(currRequest, a.getHerf());
				}
			});
			System.out.println(DateTimeStyle.duration(startTime)+"\n");
		}
	}
	
	private void getNextPage(HttpRequest currRequest, String nextUrl) {
		String nexturl = replaceWWW(nextUrl);
		System.out.println("nextUrl====>" + nexturl);
		if (JudgeUtil.isPresent(nexturl)) {
			SchedulerContext.into(currRequest.subRequest(nexturl));
			
		}

	}

	private String replaceWWW(String nextUrl) {
		if (JudgeUtil.isPresent(nextUrl)) {
			String replace = StringUtils.replace(nextUrl, "www", "m");
			return replace;
		}
		return nextUrl;
	}

	
	

}
